package com.example.pclimb.model;

import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import androidx.room.Ignore;

import java.util.Date;

/**
 * 陪爬申请实体类
 */
@Entity(tableName = "climb_requests",
        foreignKeys = {
                @ForeignKey(entity = User.class,
                        parentColumns = "id",
                        childColumns = "userId",
                        onDelete = ForeignKey.CASCADE),
                @ForeignKey(entity = User.class,
                        parentColumns = "id",
                        childColumns = "guideId",
                        onDelete = ForeignKey.SET_NULL)
        },
        indices = {
                @Index("userId"),
                @Index("guideId")
        })
public class ClimbRequest {
    @PrimaryKey(autoGenerate = true)
    private int id;
    private int userId; // 游客ID
    private Integer guideId; // 陪爬人员ID，匹配成功后填充
    private String location; // 地点
    private Date requestDate; // 请求日期
    private Date climbDate; // 陪爬日期
    private int numberOfPeople; // 人数
    private String requirements; // 主要诉求
    private int status; // 状态：0-待匹配，1-已匹配，2-待支付，3-已完成（已支付），4-已取消
    private double price; // 费用
    private double budget; // 预算
    private boolean isPaid; // 是否已支付
    
    // 状态常量
    public static final int STATUS_PENDING = 0;    // 待匹配
    public static final int STATUS_MATCHED = 1;    // 已匹配
    public static final int STATUS_AWAITING_PAYMENT = 2;       // 待支付
    public static final int STATUS_COMPLETED = 3;  // 已完成（已支付）
    public static final int STATUS_CANCELLED = 4;  // 已取消

    @Ignore
    public ClimbRequest() {
    }



    public ClimbRequest(int userId, String location, Date requestDate, Date climbDate, int numberOfPeople, String requirements, double budget) {
        this.userId = userId;
        this.location = location;
        this.requestDate = requestDate;
        this.climbDate = climbDate;
        this.numberOfPeople = numberOfPeople;
        this.requirements = requirements;
        this.budget = budget;
        this.status = STATUS_PENDING; // 初始状态为待匹配
        this.isPaid = false;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public Integer getGuideId() {
        return guideId;
    }

    public void setGuideId(Integer guideId) {
        this.guideId = guideId;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public Date getRequestDate() {
        return requestDate;
    }

    public void setRequestDate(Date requestDate) {
        this.requestDate = requestDate;
    }

    public Date getClimbDate() {
        return climbDate;
    }

    public void setClimbDate(Date climbDate) {
        this.climbDate = climbDate;
    }

    /**
     * 获取日期字符串
     * @return 日期字符串，格式为yyyy-MM-dd
     */
    public String getDate() {
        if (climbDate == null) {
            return "";
        }
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd", java.util.Locale.getDefault());
        return sdf.format(climbDate);
    }

    public int getNumberOfPeople() {
        return numberOfPeople;
    }

    public void setNumberOfPeople(int numberOfPeople) {
        this.numberOfPeople = numberOfPeople;
    }

    public String getRequirements() {
        return requirements;
    }

    public void setRequirements(String requirements) {
        this.requirements = requirements;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getBudget() {
        return budget;
    }

    public void setBudget(double budget) {
        this.budget = budget;
    }

    public boolean isPaid() {
        return isPaid;
    }

    public void setPaid(boolean paid) {
        isPaid = paid;
    }
} 